import urllib.request
import re

def open_url(url):
    req = urllib.request.Request(url)
    req.add_header('User_Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')
    page = urllib.request.urlopen(req)
    html = page.read().decode('utf-8')
    return html

def get_img(html):
    p = r'src="(http://imgsrc.baidu.com/forum/w%[^"]+\.jpg)"'
    imglist = re.findall(p,html)

    for each in imglist:
        #print(each)
        filename = each.split("/")[-1]
        urllib.request.urlretrieve(each,filename,None)
        

if __name__ == '__main__':
    url = "http://tieba.baidu.com/p/5208856742"
    get_img(open_url(url))
